package controller;

import java.awt.event.ItemListener;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.jasper.tagplugins.jstl.core.Out;

import bean.FirstCategory;
import bean.Goods;
import bean.GoodsImg;
import bean.SecondCategory;
import bean.ThirdCategory;
import common.BaseServlet;
import service.GoodsDAO;
import service.adminGoodsDAO;

/**
 * Servlet implementation class adminGoodList
 */
@WebServlet("/adminGoodList")
public class adminGoodList extends BaseServlet {
	private static final long serialVersionUID = 1L;
	GoodsDAO gDAO=new GoodsDAO();
	adminGoodsDAO agdao=new adminGoodsDAO();
    private final int pagesize=2;//分页的单页数据条数
    /**
     * @see HttpServlet#HttpServlet()
     */
    public adminGoodList() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public String goodsListForSearch(HttpServletRequest request, HttpServletResponse response) throws IOException {
		return null;
    	
	}

	@Override
	public String basefun(HttpServletRequest request, HttpServletResponse response) throws IOException{
		// TODO Auto-generated method stub
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");

		PrintWriter out;
		out = response.getWriter();
		//获取页数
		String viewStr=request.getParameter("viewPage");
		int viewPage=(viewStr==null)?1:Integer.parseInt(viewStr);
		request.setAttribute("currentPage", viewPage);
    	out.println("viewPage:"+viewPage);
    	System.out.println(viewPage);
		List<Goods> list=new ArrayList<Goods>();
		//获取商品数据
		list=agdao.queryAllGoods(pagesize,viewPage);
		System.out.println(list.size());
		//获取商品数据总条数
		int listCount=agdao.listAll();
		request.setAttribute("listCount", listCount);
		HttpSession session=request.getSession();
		session.setAttribute("list", list); 
		//List<Goods> list1=new ArrayList<Goods>();
		//list1=agdao.getImg(goodsid);
		//步骤：1.根据second_category查找该id下所有的三级分类商品存入一个list集合中
		//2.根据三级商品的id到tc_img表下找到id对应的标题图片，与三级分类商品存入一个json字符串里
		//3.将json字符串里保存在request请求中，以及选择的二级分类id和三级分类id
		//将商品信息保存在json字符串里
		StringBuffer itemsList=new StringBuffer();
		itemsList.append("[");
		for(int i=0;i<list.size();i++) {
			Goods goods=list.get(i);
			itemsList.append("{\"goodsid\":\""+goods.getGoodsid()+"\",");
			itemsList.append("\"name\":\""+goods.getName()+"\",");
			itemsList.append("\"price\":\""+goods.getPrice()+"\",");
			itemsList.append("\"cost\":\""+goods.getCost()+"\",");
			itemsList.append("\"count\":\""+goods.getCount()+"\",");
			itemsList.append("\"ifonsale\":\""+goods.getIfonsale()+"\",");
			itemsList.append("\"discount_price\":\""+goods.getDiscountPrice()+"\",");
			itemsList.append("\"post_fee\":\""+goods.getPostFee()+"\",");
			int goodsid=goods.getGoodsid();
			int third=goods.getThirdCategoryid();
			int second=gDAO.queryByTcid(third).get(0).getSecondCategoryid();
			int first=gDAO.queryByScid(second).get(0).getFirstCategoryid();
			String classify1=gDAO.queryByFcid(first).get(0).getName();
			String classify2=gDAO.queryByScid(second).get(0).getName();
			itemsList.append("\"classify1\":\""+classify1+"\",");
			itemsList.append("\"classify2\":\""+classify2+"\",");
			String titleImg=agdao.getImg(goodsid).get(0).getImg01();
			if (i==list.size()-1) {
				itemsList.append("\"titleImg\":\""+titleImg+"\"}");
			}
			else {
				itemsList.append("\"titleImg\":\""+titleImg+"\"},");
			}
		}
		itemsList.append("]");
		request.setAttribute("items",new String(itemsList));
		
		return "f:htjsp/AdminGoodList";
	}
	public String addGoods(HttpServletRequest request, HttpServletResponse response) throws IOException{
		
		return "f:htjsp/AdminAddGoods";
		
	}
	//商品批量上架方法
	public void onsale(HttpServletRequest request, HttpServletResponse response) throws IOException{
		PrintWriter out;
		out=response.getWriter();
		String str=request.getParameter("str");
		if(str.equals("")) {
			out.print("fail");
		}
		else {
		String[] goodsid=str.split(",");
		for(int i=0;i<goodsid.length;i++) {
			agdao.onsale(goodsid[i]);
		}
		out.print("ok");
		}
	}
	//商品批量下架架方法
	public void downsale(HttpServletRequest request, HttpServletResponse response) throws IOException{
		PrintWriter out;
		out=response.getWriter();
		String str=request.getParameter("str");
		if(str.equals("")) {
			out.print("fail");
		}
		else {
		String[] goodsid=str.split(",");
		for(int i=0;i<goodsid.length;i++) {
			agdao.downsale(goodsid[i]);
		}
		out.print("ok");
		}
	}
	//商品批量删除（伪）方法
		public void delete(HttpServletRequest request, HttpServletResponse response) throws IOException{
			PrintWriter out;
			out=response.getWriter();
			String str=request.getParameter("str");
			if(str.equals("")) {
				out.print("fail");
			}
			else {
			String[] goodsid=str.split(",");
			for(int i=0;i<goodsid.length;i++) {
				agdao.delete(goodsid[i]);
			}
			out.print("ok");
			}
		}
		//商品编辑
		public String goodsEdit(HttpServletRequest request, HttpServletResponse response) throws IOException{
			
			return "f:htjsp/goodsEdit";
			
		}
		public String goodsSearch(HttpServletRequest request, HttpServletResponse response) throws IOException{
					
					return "f:htjsp/goodsSearch";
					
				}
		
		//商品批量编辑
		public void editGoods(HttpServletRequest request, HttpServletResponse response) throws IOException{
			PrintWriter out;
			out=response.getWriter();
			String str=request.getParameter("str");
			String[] goodsid=str.split(",");
			String pp=request.getParameter("price");
			String[] price=pp.split(",");
			String cc=request.getParameter("cost");
			String[] cost=cc.split(",");
			String sell=request.getParameter("sell");
			String[] discount=sell.split(",");
			String store=request.getParameter("store");
			String[] count=store.split(",");
			String exp=request.getParameter("exp");
			String[] post=exp.split(",");
			//更新商品价格
			for(int i=0;i<goodsid.length;i++) {
				if (price[0].equals("1")&&!price[1].equals("")) {
					if (price[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getPrice();
						double price2=Double.parseDouble(price[1]);
						price1=price1+price2;
						agdao.updatePrice(price1, goodsid[i]);
					} else if(price[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getPrice();
						double price2;
						if(price[1].contains("%")) {
							price[1]=price[1].replaceAll("%", "");
							price2=Double.parseDouble(price[1])/100;
						}
						else if (price[1].contains(".")) {
							price2=Double.parseDouble(price[1]);
						}
						else {
							price2=Double.parseDouble(price[1])/100;
						}
						price1=price1+price1*price2;
						agdao.updatePrice(price1, goodsid[i]);
					}
				} else if(price[0].equals("2")&&!price[1].equals("")){
					if (price[2].equals("0")&&!price[1].equals("")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getPrice();
						double price2=Double.parseDouble(price[1]);
						price1=price1-price2;
						agdao.updatePrice(price1, goodsid[i]);
					} else if(price[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getPrice();
						double price2;
						if(price[1].contains("%")) {
							price[1]=price[1].replaceAll("%", "");
							price2=Double.parseDouble(price[1])/100;
						}
						else if (price[1].contains(".")) {
							price2=Double.parseDouble(price[1]);
						}
						else {
							price2=Double.parseDouble(price[1])/100;
						}
						price1=price1-price1*price2;
						agdao.updatePrice(price1, goodsid[i]);
					}
				}
			}
			//更新商品成本
			for(int i=0;i<goodsid.length;i++) {
				if (cost[0].equals("1")&&!cost[1].equals("")) {
					if (cost[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getCost();
						double price2=Double.parseDouble(cost[1]);
						price1=price1+price2;
						agdao.updateCost(price1, goodsid[i]);
					} else if(cost[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getCost();
						double price2;
						if(cost[1].contains("%")) {
							cost[1]=cost[1].replaceAll("%", "");
							price2=Double.parseDouble(cost[1])/100;
						}
						else if (cost[1].contains(".")) {
							price2=Double.parseDouble(cost[1]);
						}
						else {
							price2=Double.parseDouble(cost[1])/100;
						}
						price1=price1+price1*price2;
						agdao.updateCost(price1, goodsid[i]);
					}
				} else if(cost[0].equals("2")&&!cost[1].equals("")){
					if (cost[2].equals("0")&&!cost[1].equals("")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getCost();
						double price2=Double.parseDouble(cost[1]);
						price1=price1-price2;
						agdao.updateCost(price1, goodsid[i]);
					} else if(cost[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getCost();
						double price2;
						if(cost[1].contains("%")) {
							cost[1]=cost[1].replaceAll("%", "");
							price2=Double.parseDouble(cost[1])/100;
						}
						else if (cost[1].contains(".")) {
							price2=Double.parseDouble(cost[1]);
						}
						else {
							price2=Double.parseDouble(cost[1])/100;
						}
						price1=price1-price1*price2;
						agdao.updateCost(price1, goodsid[i]);
					}
				}
			}
			//更新商品折扣
			for(int i=0;i<goodsid.length;i++) {
				if (discount[0].equals("1")&&!discount[1].equals("")) {
					if (discount[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getDiscountPrice();
						double price2=Double.parseDouble(discount[1]);
						price1=price1+price2;
						agdao.updateDiscount(price1, goodsid[i]);
					} else if(discount[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getDiscountPrice();
						double price2;
						if(discount[1].contains("%")) {
							discount[1]=discount[1].replaceAll("%", "");
							price2=Double.parseDouble(discount[1])/100;
						}
						else if (discount[1].contains(".")) {
							price2=Double.parseDouble(discount[1]);
						}
						else {
							price2=Double.parseDouble(discount[1])/100;
						}
						price1=price1+price1*price2;
						agdao.updateDiscount(price1, goodsid[i]);
					}
				} else if(discount[0].equals("2")&&!discount[1].equals("")){
					if (discount[2].equals("0")&&!discount[1].equals("")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getDiscountPrice();
						double price2=Double.parseDouble(discount[1]);
						price1=price1-price2;
						agdao.updateDiscount(price1, goodsid[i]);
					} else if(discount[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getDiscountPrice();
						double price2;
						if(discount[1].contains("%")) {
							discount[1]=discount[1].replaceAll("%", "");
							price2=Double.parseDouble(cost[1])/100;
						}
						else if (discount[1].contains(".")) {
							price2=Double.parseDouble(discount[1]);
						}
						else {
							price2=Double.parseDouble(discount[1])/100;
						}
						price1=price1-price1*price2;
						agdao.updateDiscount(price1, goodsid[i]);
					}
				}
			}
			//更新商品库存
			for(int i=0;i<goodsid.length;i++) {
				if (count[0].equals("1")&&!count[1].equals("")) {
					if (count[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getCount();
						double price2=Double.parseDouble(count[1]);
						price1=price1+price2;
						agdao.updateCount(price1, goodsid[i]);
					} else if(count[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getCount();
						double price2;
						if(count[1].contains("%")) {
							count[1]=count[1].replaceAll("%", "");
							price2=Double.parseDouble(count[1])/100;
						}
						else if (count[1].contains(".")) {
							price2=Double.parseDouble(count[1]);
						}
						else {
							price2=Double.parseDouble(count[1])/100;
						}
						price1=price1+price1*price2;
						agdao.updateCount(price1, goodsid[i]);
					}
				} else if(count[0].equals("2")&&!count[1].equals("")){
					if (count[2].equals("0")&&!count[1].equals("")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getCount();
						double price2=Double.parseDouble(count[1]);
						price1=price1-price2;
						agdao.updateCount(price1, goodsid[i]);
					} else if(count[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getCount();
						double price2;
						if(count[1].contains("%")) {
							count[1]=count[1].replaceAll("%", "");
							price2=Double.parseDouble(count[1])/100;
						}
						else if (count[1].contains(".")) {
							price2=Double.parseDouble(count[1]);
						}
						else {
							price2=Double.parseDouble(count[1])/100;
						}
						price1=price1-price1*price2;
						agdao.updateCount(price1, goodsid[i]);
					}
				}
			}
			//更新商品运费
			for(int i=0;i<goodsid.length;i++) {
				if (post[0].equals("1")&&!post[1].equals("")) {
					if (post[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getPostFee();
						double price2=Double.parseDouble(post[1]);
						price1=price1+price2;
						agdao.updatePostfee(price1, goodsid[i]);
					} else if(post[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getPostFee();
						double price2;
						if(post[1].contains("%")) {
							post[1]=post[1].replaceAll("%", "");
							price2=Double.parseDouble(post[1])/100;
						}
						else if (post[1].contains(".")) {
							price2=Double.parseDouble(post[1]);
						}
						else {
							price2=Double.parseDouble(post[1])/100;
						}
						price1=price1+price1*price2;
						agdao.updatePostfee(price1, goodsid[i]);
					}
				} else if(post[0].equals("2")&&!post[1].equals("")){
					if (post[2].equals("0")) {
						double price1=agdao.getGoods(goodsid[i]).get(0).getPostFee();
						double price2=Double.parseDouble(post[1]);
						price1=price1-price2;
						agdao.updatePostfee(price1, goodsid[i]);
					} else if(post[2].equals("1")){
						double price1=agdao.getGoods(goodsid[i]).get(0).getPostFee();
						double price2;
						if(post[1].contains("%")) {
							post[1]=post[1].replaceAll("%", "");
							price2=Double.parseDouble(post[1])/100;
						}
						else if (post[1].contains(".")) {
							price2=Double.parseDouble(post[1]);
						}
						else {
							price2=Double.parseDouble(post[1])/100;
						}
						price1=price1-price1*price2;
						agdao.updatePostfee(price1, goodsid[i]);
					}
				}
			}
			out.print("ok");
		} 
		
		//商品检索
		public String searchGoods(HttpServletRequest request, HttpServletResponse response) throws IOException{
			response.setCharacterEncoding("UTF-8");
			request.setCharacterEncoding("UTF-8");
			List<Goods> list=new ArrayList<Goods>();
			List<Goods> list2=new ArrayList<Goods>();
			List<ThirdCategory> list1=new ArrayList<ThirdCategory>();
			PrintWriter out;
			out = response.getWriter();
			//获取检索方式
			String type=request.getParameter("type");
			//获取检索字段
			String content=request.getParameter("content");
			String count=request.getParameter("count");
			String ifonsale=request.getParameter("ifonsale");
			String laber=request.getParameter("laber");
			String priceDown=request.getParameter("priceDown");
			String priceUp=request.getParameter("priceUp");
			//根据字段模糊查询
			if (!content.equals("")&&count.equals("")&&ifonsale.equals("")&&laber.equals("")&&priceDown.equals("")&&priceUp.equals("")) {
				if (type.equals("name")) {
					//模糊查询
					list1=agdao.queryBySearchWord(content);
					for(int i=0;i<list1.size();i++) {
						list2=agdao.queryGoodsByTcid(list1.get(i).getThirdCategoryid());
						list.addAll(list2);
					}
					
				} else {
					list=agdao.getGoods(content);
				}
			} else if(!count.equals("")||!ifonsale.equals("")||!laber.equals("")&&priceDown.equals("")&&priceUp.equals("")&&content.equals("")){
				if (!count.equals("")&&ifonsale.equals("")&&laber.equals("")) {
					if (count.equals("0")) {
						list=agdao.queryGoodsByCount0();
					} else if(count.equals("9")){
						list=agdao.queryGoodsByCount10();
					}
					else if (count.equals("10-100")) {
						list=agdao.queryGoodsByCount100();
					}
					else if (count.equals("100+")) {
						list=agdao.queryGoodsByCount101();
					}
				} else if(count.equals("")&&!ifonsale.equals("")&&laber.equals("")){
					list=agdao.queryGoodsByIfonsale(ifonsale);
				}
				else if (count.equals("")&&ifonsale.equals("")&&!laber.equals("")) {
					list1=agdao.queryGoodsByLaber(laber);
					for(int i=0;i<list1.size();i++) {
						list2=agdao.queryGoodsByTcid(list1.get(i).getThirdCategoryid());
						list.addAll(list2);
					}
				}
			}else if (!priceDown.equals("")||!priceUp.equals("")&&content.equals("")&&count.equals("")&&ifonsale.equals("")&&laber.equals("")) {
				if(!priceDown.equals("")&&priceUp.equals("")) {
					list=agdao.queryGoodsByPriceDown(priceDown);
				}
				else if (priceDown.equals("")&&!priceUp.equals("")) {
					list=agdao.queryGoodsByPriceUP(priceUp);
				}
				else {
					list=agdao.queryGoodsByPrice(priceDown, priceUp);
				}
			}
			//获取商品数据
			/*list=agdao.queryGoodsByTcid(tcid, viewPage, viewPage)(pagesize,viewPage);*/
			
			//获取商品数据总条数
			int listCount=list.size();
			request.setAttribute("listCount", listCount);
			HttpSession session=request.getSession();
			session.setAttribute("list", list); 
			StringBuffer itemsList=new StringBuffer();
			itemsList.append("[");
			for(int i=0;i<list.size();i++) {
				Goods goods=list.get(i);
				itemsList.append("{\"goodsid\":\""+goods.getGoodsid()+"\",");
				itemsList.append("\"name\":\""+goods.getName()+"\",");
				itemsList.append("\"price\":\""+goods.getPrice()+"\",");
				itemsList.append("\"cost\":\""+goods.getCost()+"\",");
				itemsList.append("\"count\":\""+goods.getCount()+"\",");
				itemsList.append("\"ifonsale\":\""+goods.getIfonsale()+"\",");
				itemsList.append("\"discount_price\":\""+goods.getDiscountPrice()+"\",");
				itemsList.append("\"post_fee\":\""+goods.getPostFee()+"\",");
				int goodsid=goods.getGoodsid();
				int third=goods.getThirdCategoryid();
				int second=gDAO.queryByTcid(third).get(0).getSecondCategoryid();
				int first=gDAO.queryByScid(second).get(0).getFirstCategoryid();
				String classify1=gDAO.queryByFcid(first).get(0).getName();
				String classify2=gDAO.queryByScid(second).get(0).getName();
				itemsList.append("\"classify1\":\""+classify1+"\",");
				itemsList.append("\"classify2\":\""+classify2+"\",");
				String titleImg=agdao.getImg(goodsid).get(0).getImg01();
				if (i==list.size()-1) {
					itemsList.append("\"titleImg\":\""+titleImg+"\"}");
				}
				else {
					itemsList.append("\"titleImg\":\""+titleImg+"\"},");
				}
			}
			itemsList.append("]");
			request.setAttribute("items",new String(itemsList));
			return "f:htjsp/goodsForSearch";
		}
		
		public String ClassifyList(HttpServletRequest request, HttpServletResponse response) throws IOException{
			response.setCharacterEncoding("UTF-8");
			request.setCharacterEncoding("UTF-8");
			PrintWriter out;
			out = response.getWriter();
			List<FirstCategory> list1=new ArrayList<FirstCategory>();
			List<SecondCategory> list2=new ArrayList<SecondCategory>();
			List<ThirdCategory> list3=new ArrayList<ThirdCategory>();
			FirstCategory first=new FirstCategory();
			SecondCategory second =new SecondCategory();
			ThirdCategory third=new ThirdCategory();
			list1=agdao.queryAllFirst();
			int firstid[] = new int[list1.size()] ;
			int count=0;
			int num=agdao.listThird();
			StringBuffer itemsList=new StringBuffer();
			itemsList.append("[");
			for (int i = 0; i <list1.size(); i++) {
				firstid[i]=list1.get(i).getFirstCategoryid();
				list2=agdao.querySecondID(firstid[i]);
				System.out.println("first:"+firstid[i]);
				int secondid[] = new int[list2.size()];
				for (int j = 0; j < list2.size(); j++) {
					secondid[j]=list2.get(j).getSecondCategoryid();
					System.out.println("second:"+secondid[j]);
					list3=agdao.queryThird(secondid[j]);
					int thirdid[] = new int[list3.size()];
					for (int k = 0; k < list3.size(); k++) {
						thirdid[k]=list3.get(k).getThirdCategoryid();
						System.out.println("third:"+thirdid[k]);
						first=list1.get(i);
						second=list2.get(j);
						third=list3.get(k);
						itemsList.append("{\"firstid\":\""+first.getFirstCategoryid()+"\",");
						itemsList.append("\"secondid\":\""+second.getSecondCategoryid()+"\",");
						itemsList.append("\"thirdid\":\""+third.getThirdCategoryid()+"\",");
						itemsList.append("\"firstname\":\""+first.getName()+"\",");
						itemsList.append("\"secondname\":\""+second.getName()+"\",");
						if (count==num-1) {
							itemsList.append("\"thirdname\":\""+third.getName()+"\"}");
						}
						else {
							itemsList.append("\"thirdname\":\""+third.getName()+"\"},");
							if (list3!=null) {
								count++;
								System.out.println(count);
							}
						}
						
					}
					
				}
			}
			itemsList.append("]");
			request.setAttribute("items",new String(itemsList));
			System.out.println(itemsList);
			return "f:htjsp/ClassifyList";
			
		}
		
		public String getFirst(HttpServletRequest request, HttpServletResponse response) throws IOException{
			response.setCharacterEncoding("UTF-8");
			request.setCharacterEncoding("UTF-8");
			PrintWriter out;
			out = response.getWriter();
			//获取所有一级分类
			List<FirstCategory> list1=new ArrayList<FirstCategory>();
			list1=agdao.queryAllFirst();
			HttpSession session=request.getSession();
			session.setAttribute("list1", list1); 
			
			return "f:htjsp/addClassify";
		}
		
		public void getSecond(HttpServletRequest request, HttpServletResponse response) throws IOException{
			response.setCharacterEncoding("UTF-8");
			request.setCharacterEncoding("UTF-8");
			PrintWriter out;
			out = response.getWriter();
			int firstid=Integer.parseInt(request.getParameter("firstid"));
			System.out.println(firstid);
			//获取所有二级分类
			HttpSession session=request.getSession();
			List<SecondCategory> list2=new ArrayList<SecondCategory>();
			list2=agdao.querySecondID(firstid);
			session.setAttribute("list2", list2); 
			
			
			StringBuffer sb=new StringBuffer();
			for(int i=0;i<list2.size();i++){
			sb.append(list2.get(i).getSecondCategoryid()).append("=").append(list2.get(i).getName());
			if(i!=list2.size()-1){
			sb.append(",");
			}
			}
			System.out.println(list2.get(2).getName());
			//servlet不转向或重定向到任何页面，使用resp.getWriter().print()方法可以把文本响应给XMLHttpRequest对象
			System.out.println(sb.toString());
			out.print(sb.toString());
			out.flush();
			out.close();
		}
		

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
		
	

}
